package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Painting;

@Repository
public interface PaintingRepository extends JpaRepository<Painting, Integer> {

	@Query("select p from Painting p where p.customer.id = ?1")
	Collection<Painting> findByCustomer(int customerId);

	@Query("select p from Painting p where p.gallery.id = ?1")
	Collection<Painting> findByGallery(int galleryId);

	@Query("select p from Painting p where p.comments.size=(select max (pp.comments.size)from Painting pp)")
	Collection<Painting> findByMoreComments();
	
	@Query("select distinct p from Painting p join p.ownershipHistories h where h.customer.id = ?1 and h.actualOwner = true")
	Collection<Painting> findOwnedPaintings(int customerId);
}
